package ru.evreke.ui

import ClientMessage
import JoinMessage
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import org.jetbrains.compose.web.dom.Li
import org.jetbrains.compose.web.dom.Text
import org.jetbrains.compose.web.dom.Ul

@Composable
fun Games(
    games: MutableState<List<String>>,
    sendChannel: Channel<ClientMessage>,
    scope: CoroutineScope
) {
    Ul {
        games.value.forEach { gameId ->
            Li({
                onClick {
                    scope.launch { sendChannel.send(JoinMessage(gameId)) }
                }
            }) {
                Text(gameId)
            }
        }
    }
}